<template>
    <view class="content">
        <view class="u-p-20">
            <u-search placeholder="请输入名称" v-model="keyword" :show-action="false" bg-color="#fff" @search="doSearch"></u-search>
        </view>
        <!-- 经纪人 -->
        <view class="nav" v-if="role == 2">
            <view :class="{active : tab == 1}" @click="chooseNav(1)">本区</view>
            <view :class="{active : tab == 2}" @click="chooseNav(2)">大区</view>
        </view>
        <!-- 门店店长 -->
        <!-- <view class="nav" v-if="type == 2">
            <view :class="{active : tab == 1}" @click="chooseNav(1)">自己的</view>
            <view :class="{active : tab == 2}" @click="chooseNav(2)">大区的</view>
        </view> -->
        <!-- user_status 1启用 2禁用 work_status 1在职 2离职 3申请离职 -->
        <!-- user_type 1运维经理 2运维总监 3项目驻场 4项目总监 5经纪人 6店长 7管理员 8报备专员 9策划 -->
        <view class="item" v-for="(item,index) in list" :key='index' @click="$gTo('/staff/pages/shopowner/broker-details?id='+ item.id)">
            <view class="u-flex">
				<image :src="item.image || '../../../static/icon/avatar.png'" class="avatar"></image>
				<view class="u-flex-1">
				    <view class="name">{{item.user_name}}</view>
				    <view>手机号：{{item.phone}}</view>
				    <view>待结佣：{{item.pending_money}}元</view>
				</view>
			</view>
			
			<!-- status=1审核，任何状态都能删除 -->
			<view class="btns">
			    <view class="ck-btn" v-if="user_type == 6" @click.stop="del(item)">删除</view>
			    <view class="lx-btn" v-if="user_type == 6 && item.status == 1" @click.stop="doExamine(2,item)">通过认证</view>
			    <view class="btn" @click.stop="toChat(item)">微聊</view>
			</view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [], 
                keyword: '',
                type: 1, 
                tab: 1, //1本区 2大区
                role: '',
				show: false,
				content: '',
				user_type: '',
            }
        },
        onLoad(option) {
            this.type = option.type
			
            if (option.role) {
                this.role = option.role
            }
            
            if (this.type == 1) {
                uni.setNavigationBarTitle({
                	title:'运维经理'
                })
            }
            if (this.type == 3) {
                uni.setNavigationBarTitle({
                	title:'项目驻场'
                })
            }
            if (this.type == 5) {
                uni.setNavigationBarTitle({
                	title:'经纪人'
                })
            }
            if (this.type == 6) {
                uni.setNavigationBarTitle({
                	title:'店长'
                })
            }
			
			if (this.$getSync('userType')) {
				this.user_type = this.$getSync('userType')
			}
			
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
			del(item) {
			    uni.showModal({
			    	title: '提示',
			    	content: '确定删除吗？',
			    	confirmColor:'#033685',
			    	success: (res) => {
			            if (res.confirm) {
			                this.$ajax('user_delete', {
			                	user_token: this.$getSync('userToken'),
			                	id: item.id,
			                }).then(ret => {
			                	if (ret.success == 1000) {
			                		this.$toast('删除成功');
			                        setTimeout(() => {
			                            this.doSearch()
			                        }, 500)
			                	} else {
			                		this.$toast(ret.msg);
			                	}
			                });
			            } else if (res.cancel) {
			                
			            }
			    	}
			    });
			},
			
			// 审核
			doExamine(num, item) {
			    this.$ajax('reporting_examine', {
			        user_token: this.$getSync('userToken'),
			        id: item.id, //报备id
			        status: 7, //1报备 2到访 3认购 4认购信息 5结佣 6退户 7认证
			        examine: num, //2通过 3驳回
			        reason: '', //驳回原因
			    }).then(ret => {
			        if (ret.success == 1000) {
			            this.show = false
			            this.$toast('提交成功');
			            setTimeout(() => {
			                this.doSearch()
			            }, 500)
			        } else {
			            this.$toast(ret.msg);
			        }
			    });
			},
			
            // 微聊
            toChat(item) {
                this.$gTo('/pages/chat/chat-details?data=' + JSON.stringify(item))
            },
            
            chooseNav(num) {
                if (this.tab == num) return
                this.tab = num
                this.doSearch()
            },
            doSearch() {
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('my_personnel', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    user_type: this.type,//1运维经理 3项目驻场 5经纪人 6店长
                    status: this.role == 2 ? this.tab : '',//1本区 2大区
                    name: this.keyword,//搜索
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail.data.length > 0) {
            				this.list = this.list.concat(ret.detail.data);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        },
    }
</script>

<style lang="scss">
	.popup {
	    width: 100vw;
	    height: 100vh;
	    display: flex;
	    align-items: center;
	    justify-content: center;
	    flex-direction: column;
	}
	
	.win-box2 {
	    width: 80vw;
	    background-color: #fff;
	    border-radius: 20upx;
	}
	
	.pop-cen {
	    padding: 50rpx 20rpx;
	}
	
	.pop-tit {
	    font-size: 36rpx;
	    font-weight: bold;
	    text-align: center;
	    padding-bottom: 25rpx;
	}
	
	
	textarea {
	    width: 100%;
	    padding: 15rpx;
	    border-radius: 10rpx;
	    background-color: #f5f5f5;
	    margin-top: 15rpx;
	}
	
	.pop-btn {
	    display: flex;
	    justify-content: space-between;
	    align-items: center;
	    border-top: 2rpx solid #e6e6e6;
	}
	
	.pop-btn>view {
	    width: calc(80vw / 2);
	    text-align: center;
	    padding: 35rpx 0;
	    font-size: 30rpx;
	    color: #00a1e9;
	}
	
	.pop-btn>view:first-child {
	    border-right: 2rpx solid #e6e6e6;
	}
	
	.btns {
	    display: flex;
	    justify-content: flex-end;
	    align-items: center;
		padding-top: 15rpx;
	}
	
	.btns>view {
	    font-size: 26rpx;
	    line-height: 1;
	    padding: 15rpx 18rpx;
	    border-radius: 50rpx;
	    margin-left: 15rpx;
	    box-sizing: border-box;
	}
	
	.lx-btn {
	    color: #fff;
	    background-color: #00a1e9;
	}
	
	.ck-btn {
	    background-color: #f0f0f0;
	}
	
    page {
        background: #f5f5f5;
    }
    // .content{
    //     padding: 20rpx 0;
    // }
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20rpx;
        background-color: #fff;
    }
    .nav>view{
        width: calc(100vw / 2);
        padding: 30rpx 0;
        font-size: 26rpx;
        text-align: center;
    }
    .active{
        font-size: 28rpx;
        font-weight: bold;
        color: #00a1e9;
        border-bottom: 2rpx solid #00a1e9;
    }
    .item{
        background-color: #fff;
        border-radius: 20rpx;
        padding: 30rpx 25rpx;
        margin: 0 20rpx 20rpx;
        font-size: 24rpx;
    }
    .avatar{
        width: 88rpx;
        height: 88rpx;
        border-radius: 50%;
        margin-right: 20rpx;
    }
    .name{
        font-size: 32rpx;
        font-weight: bold;
        padding-bottom: 10rpx;
    }
    .btn{
        color: #fff;
        line-height: 1;
        padding: 10rpx 18rpx;
        background-color: #09bb07;
        border-radius: 50rpx;
        margin-left: 10rpx;
    }
    
    
</style>

